﻿//=================================MakeHistogramAlgorithm.cs============================\\
//===Bart Steijlen======\\


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms.DataVisualization.Charting;
using System.Windows.Forms;
using System.IO;


namespace Team2_Vision
{
    class MakeHistogram : HistoAlgorithm
    {
        public MakeHistogram(String name) : base(name) { }

        
        public override int[] DoAlgorithm(System.Drawing.Bitmap sourceImage){

            Bitmap newbmp = new Bitmap(sourceImage.Width, sourceImage.Height);

            int[] histo_255 = new int[256];
            
            for (int i = 0; i < sourceImage.Width; i++)
            {
                for (int j = 0; j < sourceImage.Height; j++)
                {

                    Color originalColor = sourceImage.GetPixel(i, j);

                    
                    int grayScale = (int)((originalColor.R * .3) + (originalColor.G * .59)
                        + (originalColor.B * .11));


                    Color newColor = Color.FromArgb(grayScale, grayScale, grayScale);

                    newbmp.SetPixel(i, j, newColor);
                  
                    //count the values in an array for the histogram
                    histo_255[grayScale] = histo_255[grayScale] + 1;
                  

                }
            }




            return histo_255;
        }
        
        }       

           
            

        


     
    }

